#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.demo.module.foo.controller;

import ${package}.common.bean.vo.JsonResult;
import ${package}.common.component.service.CodeService;
import ${package}.common.emum.ReturnCodeEnum;
import ${package}.demo.bean.vo.FooVo;
import ${package}.demo.bean.vo.UpdateFooVo;
import ${package}.demo.module.foo.service.FooService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * Description: 示例Controller
 *
 * @author wenxiaopeng
 * @date 2021/06/23 11:33
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Slf4j
@Validated
@RestController
@Api(description = "示例工程Controller")
public class FooController {

	@Resource
	private FooService fooService;

	@Resource
	private CodeService codeService;

	@PostMapping("/foo/{name}")
	@ApiOperation("新增Foo信息")
	@ApiImplicitParam(name = "name", value = "名称", required = true)
	public JsonResult<FooVo> addFooInfo(@PathVariable("name") String name) {

		FooVo newFoo = fooService.addFoo(name);
		return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, newFoo);
	}

	@PostMapping("/foo")
	@ApiOperation("修改Foo信息")
	public JsonResult updateFooInfo(@RequestBody @Valid UpdateFooVo updateFooVo) {

		fooService.updateFoo(updateFooVo);
		return JsonResult.getInstant(ReturnCodeEnum.SUCCESS);
	}

	@GetMapping("/codes")
	public JsonResult getCodes(String type) {
		return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, codeService.getCodeTypeTree(type, null, false));
	}
}

